package com.fastloan.jn.mgt.customermanager.weekly.controller;

import com.fastloan.jn.mgt.customermanager.basic.service.JnCustomerManagerService;
import com.fastloan.jn.mgt.customermanager.daily.service.JnCustomerManagerDailyService;
import com.fastloan.jn.mgt.customermanager.weekly.model.JnCustomerManagerWeekly;
import com.fastloan.jn.mgt.customermanager.weekly.service.JnCustomerManagerWeeklyService;
import com.fastloan.jn.utils.other.ObjUtil;
import com.fastloan.safe.core.util.ManagerKit;
import com.kawins.base.baseabs.BaseController;
import com.kawins.result.ResultEnum;
import com.kawins.result.ResultTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yanwe
 * createTime 2017-10-2017/10/19 14:21
 */
@RestController
@RequestMapping("/api/web/customerManagerWeekly")
public class JnCustomerManagerWeeklyController extends BaseController<JnCustomerManagerWeekly>{

    @Autowired
    private JnCustomerManagerWeeklyService jnCustomerManagerWeeklyService;

    @Autowired
    private JnCustomerManagerDailyService managerDailyService;

    @Autowired
    private JnCustomerManagerService customerManagerService ;


    @GetMapping
    public ResultTo getDaily() {
        jnCustomerManagerWeeklyService.initWeekly();
        return new ResultTo();
    }

    @PostMapping("/weeklies")
    public ResultTo weeklies( String cname) {
        //@Todo 多角色
        List<String> managerIds = managerDailyService.topOrgManagerIds(ManagerKit.getTopOrgId());
        if(managerIds == null || managerIds.size() == 0){
            return new ResultTo(ResultEnum.PARAM_ERROR);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("list",managerIds);
        if(!ObjUtil.isEmpty(cname)) { map.put("cname",cname.replace("#",""));}
        return dataPage("managerWeekLyExts",map);
    }

    @GetMapping("/weekly/{weeklyId}")
    public ResultTo getWeekly(@PathVariable("weeklyId") String weeklyId){
        return new ResultTo().setData(jnCustomerManagerWeeklyService.selectByPrimaryKey(weeklyId));
    }


}
